import { BreezeAction, RootState } from "../interface/state";
import { ServiceActionType } from "../utils/constant";
import { mutationActionType } from "../utils/mutation";
import { set } from 'lodash';

let initialState = {};

export default (state: RootState = initialState, action: BreezeAction) => {
  if (action.type === mutationActionType(action)) {

  }
  switch (action.type) {
    case ServiceActionType.StoreMutation:
      if (action.which.field === '*') {
        state = { ...state, ...action.payload };
      } else {
        state = JSON.parse(JSON.stringify(set(state, action.which.field, action.payload)));
      }
      break;
  }
  console.log('state.............', state)
  return state;
}